package org.zhuxian.cn.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zhuxian.cn.entity.DTO.EquipmentBuildsDTO;
import org.zhuxian.cn.entity.DTO.EquipmentBuildsDeleteDTO;
import org.zhuxian.cn.result.JsonResult;
import org.zhuxian.cn.service.EquipmentBuildsService;

@RestController
@RequestMapping("/equipment/builds")
@Api(tags = "装备配装管理", description = "装备配装相关接口")
public class EquipmentBuildsController {
    @Autowired
    private EquipmentBuildsService equipmentBuildsServer;

    @ApiOperation(value = "获取职业推荐配装", notes = "根据职业名称获取推荐的装备配装方案")
    @GetMapping("/recommend/{className}")
    public JsonResult getRecommendByClassName(@ApiParam(value = "职业名称") @PathVariable String className) {
        return new JsonResult(200, "OK", equipmentBuildsServer.getRecommendEquipmentBuilds(className));
    }

    @ApiOperation(value = "获取所有职业推荐配装", notes = "获取所有职业的推荐装备配装方案")
    @GetMapping("/recommend")
    public JsonResult getRecommendBuilds() {
        return new JsonResult(200, "OK", equipmentBuildsServer.getRecommendEquipmentBuilds());
    }

    @ApiOperation(value = "获取全部配装", notes = "获取系统中所有的装备配装方案")
    @GetMapping("/recommend/all")
    public JsonResult getAllEquipmentBuilds() {
        return new JsonResult(200, "OK", equipmentBuildsServer.getAllEquipmentBuilds());
    }

    @ApiOperation(value = "获取用户配装", notes = "获取指定用户的所有装备配装方案")
    @GetMapping("/user/{userId}")
    public JsonResult getRecommendBuildsByUserId(@ApiParam(value = "用户ID") @PathVariable Long userId) {
        return new JsonResult(200, "OK", equipmentBuildsServer.getEquipmentBuildsByUserId(userId));
    }

    @ApiOperation(value = "获取配装详情", notes = "根据配装ID获取装备配装方案详细信息")
    @GetMapping("/{id}")
    public JsonResult getEquipmentBuildsById(@ApiParam(value = "配装ID") @PathVariable int id) {
        return new JsonResult(200, "OK", equipmentBuildsServer.getEquipmentBuildsById(id));
    }

    @ApiOperation(value = "配装点赞", notes = "为指定配装增加点赞数")
    @GetMapping("/like/{id}")
    public JsonResult addLikeCountStatistics(@ApiParam(value = "配装ID") @PathVariable int id) {
        equipmentBuildsServer.addLikeCountStatistics(id);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "新增配装", notes = "添加新的装备配装方案")
    @PostMapping
    public JsonResult addEquipmentBuilds(@ApiParam(value = "配装信息") @RequestBody EquipmentBuildsDTO equipmentBuildsDTO) {
        equipmentBuildsServer.addEquipmentBuilds(equipmentBuildsDTO);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "删除配装", notes = "根据配装ID删除装备配装方案")
    @GetMapping("/del/{id}")
    public JsonResult addEquipmentBuilds(@ApiParam(value = "配装ID") @PathVariable int id) {
        equipmentBuildsServer.deleteEquipmentBuildsById(id);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "用户删除配装", notes = "用户删除自己创建的装备配装方案")
    @PostMapping("/delete")
    public JsonResult deleteEquipmentBuilds(@ApiParam(value = "删除配装请求信息") @RequestBody EquipmentBuildsDeleteDTO equipmentBuildsDeleteDTO) {
        try {
            if (equipmentBuildsServer.delEquipmentBuildsByUserIdAndId(equipmentBuildsDeleteDTO.getId(), equipmentBuildsDeleteDTO.getUserId())) {
                return new JsonResult(200, "OK");
            }
            return new JsonResult(403, "当前配装不属于当前用户");
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult(500, "删除配装时出现错误");
        }
    }
}



